package com.haixiaoke.business;

import com.haixiaoke.common.annotation.Log;
import com.haixiaoke.common.core.domain.AjaxResult;
import com.haixiaoke.common.core.page.TableDataInfo;
import com.haixiaoke.common.enums.BusinessType;
import com.haixiaoke.common.utils.poi.ExcelUtil;
import com.haixiaoke.domain.LockOfflineLog;
import com.haixiaoke.service.ILockOfflineLogService;
import com.haixiaoke.system.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 智能锁离线记录Controller
 *
 * @author qixi
 * @date 2023-05-29
 */
@RestController
@RequestMapping("/business/offlineLog")
public class LockOfflineLogController extends BaseController {
    @Autowired
    private ILockOfflineLogService lockOfflineLogService;

    /**
     * 查询智能锁离线记录列表
     */
    @PreAuthorize("@ss.hasPermi('business:offlineLog:list')")
    @GetMapping("/list")
    public TableDataInfo list(LockOfflineLog lockOfflineLog) {
        startPage();
        List<LockOfflineLog> list = lockOfflineLogService.selectLockOfflineLogList(lockOfflineLog);
        return getDataTable(list);
    }

    /**
     * 导出智能锁离线记录列表
     */
    @PreAuthorize("@ss.hasPermi('business:offlineLog:export')")
    @Log(title = "智能锁离线记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LockOfflineLog lockOfflineLog) {
        List<LockOfflineLog> list = lockOfflineLogService.selectLockOfflineLogList(lockOfflineLog);
        ExcelUtil<LockOfflineLog> util = new ExcelUtil<LockOfflineLog>(LockOfflineLog.class);
        util.exportExcel(response, list, "智能锁离线记录数据");
    }

    /**
     * 获取智能锁离线记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:offlineLog:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(lockOfflineLogService.selectLockOfflineLogById(id));
    }

    /**
     * 新增智能锁离线记录
     */
    @PreAuthorize("@ss.hasPermi('business:offlineLog:add')")
    @Log(title = "智能锁离线记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LockOfflineLog lockOfflineLog) {
        return toAjax(lockOfflineLogService.insertLockOfflineLog(lockOfflineLog));
    }

    /**
     * 修改智能锁离线记录
     */
    @PreAuthorize("@ss.hasPermi('business:offlineLog:edit')")
    @Log(title = "智能锁离线记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LockOfflineLog lockOfflineLog) {
        return toAjax(lockOfflineLogService.updateLockOfflineLog(lockOfflineLog));
    }

    /**
     * 删除智能锁离线记录
     */
    @PreAuthorize("@ss.hasPermi('business:offlineLog:remove')")
    @Log(title = "智能锁离线记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(lockOfflineLogService.deleteLockOfflineLogByIds(ids));
    }
}
